<template>
  <div>
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      @keyup.enter.native="search()"
    >
      <el-form-item label="  兑换编号">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 200px"
          v-model="formInline.keyword"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  会员名称">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 200px"
          v-model="formInline.userName"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  会员手机号">
        <br />
        <br />
        <el-input
          style="margin-left: -70px; width: 200px"
          v-model="formInline.cellPhoneNo"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="  大区名称">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 200px"
          v-model="formInline.upOrgZone"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  营销区域名称">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 200px"
          v-model="formInline.baseName"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  店铺名称">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 200px"
          v-model="formInline.storeName"
          clearable
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label>
                <el-input
                    v-model="formInline.storeOwnerName"
                    placeholder="请输入店主姓名"
                    clearable
                ></el-input>
            </el-form-item> -->
      <el-form-item label="  店铺授权编码">
        <br />
        <br />
        <el-input
          style="margin-left: -80px; width: 200px"
          v-model="formInline.authCode"
          clearable
        ></el-input>
      </el-form-item>

      <el-form-item label="  品鉴酒名称">
        <br />
        <br />
        <el-input
          style="margin-left: -70px; width: 200px"
          v-model="formInline.name"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  兑换数量">
        <br />
        <br />
        <el-input
          style="width: 115px; margin-left: -60px"
          v-model="formInline.startExchangeCount"
        ></el-input
        >至
        <el-input
          style="width: 115px"
          v-model="formInline.endExchangeCount"
        ></el-input>
      </el-form-item>
      <el-form-item label="  会员等级">
        <br />
        <br />
        <el-select
          style="margin-left: -60px; width: 200px"
          v-model="formInline.gradeLevel"
          clearable
        >
          <el-option
            v-for="(send, i) in options"
            :key="i"
            :value="send.gradelevelName"
            :label="send.gradelevelName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="  配送方式">
        <br />
        <br />
        <el-select
          style="margin-left: -60px; width: 200px"
          v-model="formInline.deliveryType"
          clearable
        >
          <el-option label="五粮液总部配送" value="1"></el-option>
          <el-option label="专卖店配送" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="  物流状态">
        <br />
        <br />
        <el-select
          style="margin-left: -60px; width: 200px"
          v-model="formInline.wuliu"
          clearable
        >
          <el-option label="未发货" value="1"></el-option>
          <el-option label="已发货" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="  物流公司" v-show="showsx">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 250px"
          v-model="formInline.deliveryCompany"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  备注姓名" v-show="showsx">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 250px"
          v-model="formInline.remarkName"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  物流单号" v-show="showsx">
        <br />
        <br />
        <el-input
          style="margin-left: -60px; width: 250px"
          v-model="formInline.deliveryNo"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="  兑换单状态" v-show="showsx">
        <br />
        <br />
        <el-select
          style="margin-left: -70px; width: 250px"
          v-model="formInline.exchangeStatus"
          clearable
        >
          <el-option label="审核中" value="0"></el-option>
          <el-option label="待发货" value="1"></el-option>
          <!-- <el-option label="已发货" value="2"></el-option> -->
          <el-option label="配送中" value="3"></el-option>
          <el-option label="已完成" value="4"></el-option>
          <el-option label="已驳回" value="5"></el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label>
                <el-select v-model="formInline.bindingRelation" placeholder="请选择兑换状态" clearable>
                    <el-option label="兑换成功" value="1"></el-option>
                    <el-option label="兑换失败" value="2"></el-option>
                </el-select>
            </el-form-item> -->
      <!-- -->
      <el-form-item label="  兑换日期" v-show="showsx">
        <br />
        <br />
        <el-date-picker
          style="margin-left: -60px; width: 420px"
          v-model="formInline.dateRangeFW"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="兑换开始日期"
          end-placeholder="兑换结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="  配送日期" v-show="showsx">
        <br />
        <br />
        <el-date-picker
          style="margin-left: -60px; width: 420px"
          v-model="formInline.dateRange"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="配送开始日期"
          end-placeholder="配送结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="  完成日期" v-show="showsx">
        <br />
        <br />
        <el-date-picker
          style="margin-left: -60px; width: 420px"
          v-model="formInline.dateRangeWC"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="完成开始日期"
          end-placeholder="完成结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </el-form-item>
      <div style="width: 100%; display: flex; justify-content: flex-end">
        <el-form-item>
          <el-button type="primary" @click="showshaix()" size="mini">{{
            showval
          }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="search()"
            size="mini"
            icon="el-icon-search"
            >查询</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="kong()"
            size="mini"
            icon="el-icon-delete"
            >清空</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="showConfigTableDialog()"
            size="mini"
            icon="el-icon-setting"
            :loading="insertLoading"
            >列表配置</el-button
          >
          <el-button
            @click="exportExcel"
            style="margin-top: 0px"
            size="mini"
            type="success"
            icon="el-icon-s-data"
            :loading="exportLoading"
            >导出</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-upload
            accept=".xlsx"
            :action="action"
            :headers="headers"
            :on-success="
              (res, file, fileList) => {
                return upload(res, file, fileList);
              }
            "
            :on-change="handleChange"
            :file-list="fileList"
          >
            <el-button
              size="mini"
              type="success"
              icon="el-icon-upload"
              :loading="importLoading"
              >导入EXCEL</el-button
            >
          </el-upload>
        </el-form-item>
      </div>
    </el-form>
    <el-table
      @selection-change="selectionChangeHandle"
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      height="400px"
      :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      border
      v-loading="loading"
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
      ></el-table-column>
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="55"
      ></el-table-column>
      <el-table-column
        prop="exchangeSeq"
        label="兑换单号"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('exchangeSeq')"
      ></el-table-column>
      <el-table-column
        prop="userName"
        label="会员姓名"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('userName')"
      ></el-table-column>
      <el-table-column
        prop="remarkName"
        label="备注名称"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('remarkName')"
      ></el-table-column>
      <el-table-column
        prop="gradeLevel"
        label="会员等级"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('gradeLevel')"
      ></el-table-column>
      <el-table-column
        prop="cellPhoneNo"
        label="会员手机号"
        width="200"
        align="left"
        show-overflow-tooltip
        v-if="isShow('cellPhoneNo')"
      ></el-table-column>
      <el-table-column
        prop="upOrgZone"
        label="大区名称"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('upOrgZone')"
      ></el-table-column>
      <el-table-column
        prop="baseName"
        label="营销区域名称"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('baseName')"
      ></el-table-column>
      <el-table-column
        prop="authCode"
        label="店铺授权编码"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('authCode')"
      ></el-table-column>
      <el-table-column
        prop="storeName"
        label="店铺名称"
        width="200"
        align="left"
        show-overflow-tooltip
        v-if="isShow('storeName')"
      ></el-table-column>
      <el-table-column
        prop="storeOwnerName"
        label="店主姓名"
        width="200"
        align="left"
        show-overflow-tooltip
        v-if="isShow('storeOwnerName')"
      ></el-table-column>
      <el-table-column
        prop="exchangeCount"
        label="兑换数量(瓶)"
        width="200"
        align="left"
        show-overflow-tooltip
        v-if="isShow('exchangeCount')"
      ></el-table-column>
      <el-table-column
        prop="exchangeStatus"
        label="兑换单状态"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('exchangeStatus')"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.exchangeStatus == '0'">审核中</span>
          <span v-if="scope.row.exchangeStatus == '1'">待发货</span>
          <!-- <span v-if="scope.row.exchangeStatus == '2'">已发货</span> -->
          <span v-if="scope.row.exchangeStatus == '3'">配送中</span>
          <span v-if="scope.row.exchangeStatus == '4'">已完成</span>
          <span v-if="scope.row.exchangeStatus == '5'">已驳回</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="exchangeSeq"
        label="品鉴酒编码"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('exchangeSeq')"
      ></el-table-column>
      <el-table-column
        prop="name"
        label="品鉴酒名称"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('name')"
      ></el-table-column>

      <el-table-column
        prop="deliveryType"
        label="配送方式"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('deliveryType')"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.deliveryType == '2'">专卖店配送</span>
          <span v-if="scope.row.deliveryType == '1'">五粮液总部配送</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="兑换时间"
        width="280"
        align="left"
        show-overflow-tooltip
        v-if="isShow('createTime')"
      ></el-table-column>
      <el-table-column
        prop="deliveryCompany"
        label="物流公司"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('deliveryCompany')"
      ></el-table-column>
      <el-table-column
        prop="wuliu"
        label="物流状态"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('wuliu')"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.wuliu == '2'">已发货</span>
          <span v-if="scope.row.wuliu == '1'">未发货</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="deliveryNo"
        label="物流单号"
        width="180"
        align="left"
        show-overflow-tooltip
        v-if="isShow('deliveryNo')"
      ></el-table-column>
      <el-table-column
        prop="deliveryTime"
        label="配送时间"
        width="280"
        align="left"
        show-overflow-tooltip
        v-if="isShow('deliveryTime')"
      ></el-table-column>
      <el-table-column
        prop="completeTime"
        label="完成时间"
        width="280"
        align="left"
        show-overflow-tooltip
        v-if="isShow('completeTime')"
      ></el-table-column>
      <el-table-column label="操作" fixed="right" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="edit(scope.row)" type="text"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-form :inline="true" :model="formInline">
      <el-form-item style="margin-top: 6px"></el-form-item>
    </el-form>
    <div class="block" style="margin-top: -49px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30, 50, 100, 150, 200]"
        :current-page="listQuery.current"
        :page-size="listQuery.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <!--列表配置-->
    <el-dialog
      title="列表配置"
      :visible.sync="configTableDialogVisible"
      width="50%"
      @close="closeConfigTableDialog()"
    >
      <div id="configTableDiv">
        <el-form :inline="true" :model="formInline2" class="demo-form-inline">
          <el-form-item label="选择列表字段：">
            <el-checkbox
              :indeterminate="formInline2.isIndeterminate"
              v-model="formInline2.isAll"
              style="margin-top: 10px"
              @change="isAllFieldChange"
              >全选</el-checkbox
            >
          </el-form-item>
          <el-divider></el-divider>
          <el-checkbox-group
            v-model="userMenuShowFields"
            @change="isSingleFieldChange"
          >
            <el-checkbox
              v-for="item in userMenuFieldList"
              :label="item.fieldCode"
              :key="item.fieldCode"
              style="margin: 15px 10px; width: 120px"
              >{{ item.fieldName }}</el-checkbox
            >
          </el-checkbox-group>
        </el-form>
        <el-row>
          <el-col :span="24" style="text-align: center; margin-top: 30px">
            <el-button type="info" @click="closeConfigTableDialog()" size="mini"
              >取 消</el-button
            >
            <el-button
              type="primary"
              @click="insertUserFieldRelation()"
              size="mini"
              >确 认</el-button
            >
          </el-col>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryUserMenuFieldByParam,
  insertUserFieldRelation,
} from '@/api/tradeOrderSearch';
import { queryExchangeRecord, exportExchangeRecord } from '@/api/memberPrice';
import { getmemberrule } from '@/api/membergrade';
import qs from 'qs';
export default {
  data() {
    return {
      showsx: false,
      showval: '展开筛选条件',
      action: `${process.env.VUE_APP_BASE_API}/api/promotion-service/v1/WineRedPacket/importExchangeRecord`,
      headers: {},
      fileList: [],
      options: [],
      tableData: [],
      shopLevelList: [],
      dataListSelections: [],
      lsGoodsList: [],
      loading: true,
      exportLoading: false,
      importLoading: false,
      total: 0,
      listQuery: {
        current: 1,
        size: 100,
      },
      dialogVisible: false,
      dialogVisibleLevel: false,
      insertLoading: false,
      configTableDialogVisible: false, //列表配置弹窗状态
      formInline2: {
        isIndeterminate: false, //是否半选中
        isAll: true, //是否全部显示,
        menuCode: 'exchangeForm',
      },
      userMenuFieldList: [], //全部列名列表
      userMenuAllFields: [], //全部的列名
      userMenuShowFields: [], //显示的列名
      formInline: {
        keyword: '',
        userName: '',
        cellPhoneNo: '',
        authCode: '',
        upOrgZone: '',
        baseName: '',
        storeName: '',
        storeOwnerName: '',
        deliveryCompany: '',
        name: '',
        remarkName: '',
        bindingRelation: '',
        deliveryType: '',
        wuliu: '',
        exchangeStatus: '',
        gradeLevel: '',
        bindingRelation: '',
        deliveryType: '',
        isDeliver: '',
        gradelevelId: '',
        prizeLevelId: '',
        dateRange: [],
        dateRangeFW: [],
        dateRangeWC: [],
        orgSeq: '',
        orgType: 1,
      },
      rules: {},
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            },
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            },
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            },
          },
        ],
      },
    };
  },
  mounted() {
    this.headers = { token: localStorage.token || '' };
    this.logininfo = localStorage.getItem('logininfo');
    this.orgList = JSON.parse(this.logininfo).orgList;
    this.formInline.orgSeq =
      this.orgList[0].orgType == 1 ? '' : this.orgList[0].orgSeq;
    this.formInline.orgType = this.orgList[0].orgType;

    this.queryUserMenuFieldByParam(); //加载列表配置字段
    this.getDataList(); //加载列表
    this._getmemberinfo(); //会员等级
  },
  created() {},
  methods: {
    showshaix() {
      if (this.showsx == false) {
        this.showsx = true;
        this.showval = '关闭筛选条件';
      } else {
        this.showsx = false;
        this.showval = '展开筛选条件';
      }
    },
    kong() {
      this.formInline.keyword = '';
      this.formInline.userName = '';
      this.formInline.cellPhoneNo = '';
      this.formInline.upOrgZone = '';
      this.formInline.authCode = '';
      this.formInline.baseName = '';
      this.formInline.storeName = '';
      this.formInline.storeOwnerName = '';
      this.formInline.deliveryCompany = '';
      this.formInline.name = '';
      this.formInline.remarkName = '';
      this.formInline.startExchangeCount = '';
      this.formInline.endExchangeCount = '';
      this.formInline.wuliu = '';
      this.formInline.bindingRelation = '';
      this.formInline.status = '';
      this.formInline.deliveryType = '';
      this.formInline.isDeliver = '';
      this.formInline.exchangeStatus = '';
      this.formInline.gradeLevel = '';
      this.formInline.dateRange = [];
      this.formInline.dateRangeFW = [];
      this.formInline.dateRangeWC = [];
    },
    search() {
      this.loading = true;
      this.listQuery.current = 1;
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          exchangeSeq: this.formInline.keyword.trim(),
          userName: this.formInline.userName.trim(),
          cellPhoneNo: this.formInline.cellPhoneNo.trim(),
          authCode: this.formInline.authCode.trim(),
          upOrgZone: this.formInline.upOrgZone.trim(),
          baseName: this.formInline.baseName.trim(),
          storeName: this.formInline.storeName.trim(),
          storeOwnerName: this.formInline.storeOwnerName.trim(),
          deliveryCompany: this.formInline.deliveryCompany.trim(),
          name: this.formInline.name.trim(),
          remarkName: this.formInline.remarkName.trim(),
          deliveryType: this.formInline.deliveryType.trim(),
          wuliu: this.formInline.wuliu.trim(),
          gradeLevel: this.formInline.gradeLevel,
          bindingRelation: this.formInline.bindingRelation,
          isDeliver: this.formInline.isDeliver,
          exchangeStatus: this.formInline.exchangeStatus,
          startExchangeCount: this.formInline.startExchangeCount,
          endExchangeCount: this.formInline.endExchangeCount,
          beginDeliveryTime:
            this.formInline.dateRange !== null &&
            this.formInline.dateRange.length > 0
              ? this.formInline.dateRange[0]
              : '',
          endDeliveryTime:
            this.formInline.dateRange !== null &&
            this.formInline.dateRange.length > 1
              ? this.formInline.dateRange[1]
              : '',
          startCreateTime:
            this.formInline.dateRangeFW !== null &&
            this.formInline.dateRangeFW.length > 0
              ? this.formInline.dateRangeFW[0]
              : '',
          endCreateTime:
            this.formInline.dateRangeFW !== null &&
            this.formInline.dateRangeFW.length > 1
              ? this.formInline.dateRangeFW[1]
              : '',
          beginCompleteTime:
            this.formInline.dateRangeWC !== null &&
            this.formInline.dateRangeWC.length > 0
              ? this.formInline.dateRangeWC[0]
              : '',
          endCompleteTime:
            this.formInline.dateRangeWC !== null &&
            this.formInline.dateRangeWC.length > 1
              ? this.formInline.dateRangeWC[1]
              : '',
          orgSeq: this.formInline.orgSeq,
          orgType: this.formInline.orgType,
        },
      };
      queryExchangeRecord(data).then((res) => {
        this.loading = false;
        this.total = res.total;
        this.tableData = res.records;
      });
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.getDataList();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.getDataList();
    },

    getDataList() {
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        condition: {
          exchangeSeq: this.formInline.keyword.trim(),
          userName: this.formInline.userName.trim(),
          cellPhoneNo: this.formInline.cellPhoneNo.trim(),
          authCode: this.formInline.authCode.trim(),
          upOrgZone: this.formInline.upOrgZone.trim(),
          baseName: this.formInline.baseName.trim(),
          storeName: this.formInline.storeName.trim(),
          storeOwnerName: this.formInline.storeOwnerName.trim(),
          deliveryCompany: this.formInline.deliveryCompany.trim(),
          name: this.formInline.name.trim(),
          remarkName: this.formInline.remarkName.trim(),
          deliveryType: this.formInline.deliveryType.trim(),
          wuliu: this.formInline.wuliu.trim(),
          gradeLevel: this.formInline.gradeLevel,
          bindingRelation: this.formInline.bindingRelation,
          deliveryType: this.formInline.deliveryType,
          isDeliver: this.formInline.isDeliver,
          exchangeStatus: this.formInline.exchangeStatus,
          startExchangeCount: this.formInline.startExchangeCount,
          endExchangeCount: this.formInline.endExchangeCount,
          beginDeliveryTime:
            this.formInline.dateRange !== null &&
            this.formInline.dateRange.length > 0
              ? this.formInline.dateRange[0]
              : '',
          endDeliveryTime:
            this.formInline.dateRange !== null &&
            this.formInline.dateRange.length > 1
              ? this.formInline.dateRange[1]
              : '',
          startCreateTime:
            this.formInline.dateRangeFW !== null &&
            this.formInline.dateRangeFW.length > 0
              ? this.formInline.dateRangeFW[0]
              : '',
          endCreateTime:
            this.formInline.dateRangeFW !== null &&
            this.formInline.dateRangeFW.length > 1
              ? this.formInline.dateRangeFW[1]
              : '',
          beginCompleteTime:
            this.formInline.dateRangeWC !== null &&
            this.formInline.dateRangeWC.length > 0
              ? this.formInline.dateRangeWC[0]
              : '',
          endCompleteTime:
            this.formInline.dateRangeWC !== null &&
            this.formInline.dateRangeWC.length > 1
              ? this.formInline.dateRangeWC[1]
              : '',
          orgSeq: this.formInline.orgSeq,
          orgType: this.formInline.orgType,
        },
      };
      queryExchangeRecord(data).then((res) => {
        this.loading = false;
        this.total = res.total;
        this.tableData = res.records;
      });
    },

    // 多选表1
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    selectEdit() {
      // 配置列表
    },
    exportExcel() {
      let data = {
        condition: {
          exchangeSeq: this.formInline.keyword,
          userName: this.formInline.userName,
          cellPhoneNo: this.formInline.cellPhoneNo,
          authCode: this.formInline.authCode,
          upOrgZone: this.formInline.upOrgZone,
          baseName: this.formInline.baseName,
          storeName: this.formInline.storeName,
          storeOwnerName: this.formInline.storeOwnerName.trim(),
          deliveryCompany: this.formInline.deliveryCompany,
          name: this.formInline.name,
          remarkName: this.formInline.remarkName,
          deliveryType: this.formInline.deliveryType,
          wuliu: this.formInline.wuliu,
          gradeLevel: this.formInline.gradeLevel,
          bindingRelation: this.formInline.bindingRelation,
          deliveryType: this.formInline.deliveryType,
          isDeliver: this.formInline.isDeliver,
          exchangeStatus: this.formInline.exchangeStatus,
          startExchangeCount: this.formInline.startExchangeCount,
          endExchangeCount: this.formInline.endExchangeCount,
          beginDeliveryTime:
            this.formInline.dateRange !== null &&
            this.formInline.dateRange.length > 0
              ? this.formInline.dateRange[0]
              : '',
          endDeliveryTime:
            this.formInline.dateRange !== null &&
            this.formInline.dateRange.length > 1
              ? this.formInline.dateRange[1]
              : '',
          startCreateTime:
            this.formInline.dateRangeFW !== null &&
            this.formInline.dateRangeFW.length > 0
              ? this.formInline.dateRangeFW[0]
              : '',
          endCreateTime:
            this.formInline.dateRangeFW !== null &&
            this.formInline.dateRangeFW.length > 1
              ? this.formInline.dateRangeFW[1]
              : '',
          beginCompleteTime:
            this.formInline.dateRangeWC !== null &&
            this.formInline.dateRangeWC.length > 0
              ? this.formInline.dateRangeWC[0]
              : '',
          endCompleteTime:
            this.formInline.dateRangeWC !== null &&
            this.formInline.dateRangeWC.length > 1
              ? this.formInline.dateRangeWC[1]
              : '',
          orgSeq: this.formInline.orgSeq,
          orgType: this.formInline.orgType,
        },
      };
      exportExchangeRecord(data)
        .then((res) => {
          const link = document.createElement('a');
          let blob = new Blob([res], { type: 'application/vnd.ms-excel' });
          link.style.display = 'none';
          //设置连接
          link.href = URL.createObjectURL(blob);
          link.download = '商家端兑换记录列表.xlsx';
          document.body.appendChild(link);
          //模拟点击事件
          link.click();
        })
        .catch((err) => {
          console.log(err);
        });
    },

    //显示配置弹窗
    showConfigTableDialog() {
      this.configTableDialogVisible = true;
    },
    //关闭配置弹窗
    closeConfigTableDialog() {
      this.queryUserMenuFieldByParam();
      this.configTableDialogVisible = false;
    },
    //获取列表字段列表
    queryUserMenuFieldByParam() {
      let data = {
        menuCode: this.formInline2.menuCode,
      };
      this.userMenuAllFields = []; //全部的列名
      this.userMenuShowFields = []; //显示的列名
      queryUserMenuFieldByParam(data).then((res) => {
        this.userMenuFieldList = res.records;
        this.userMenuFieldList.forEach((item, index) => {
          this.userMenuAllFields.push(item.fieldCode);
          if (item.isShow == 1) {
            this.userMenuShowFields.push(item.fieldCode);
          }
        });
        if (
          this.userMenuShowFields.length == 0 ||
          this.userMenuShowFields.length == this.userMenuAllFields.length
        ) {
          this.userMenuShowFields = this.userMenuAllFields;
          this.formInline2.isAll = true;
        } else {
          this.formInline2.isAll = false;
          this.formInline2.isIndeterminate = true;
        }
      });
    },
    //保存显示字段
    insertUserFieldRelation() {
      if (
        this.userMenuShowFields == null ||
        this.userMenuShowFields.length == 0
      ) {
        this.$message({
          showClose: true,
          message: '列表字段不可为空',
          type: 'info',
        });
        return;
      }
      let data = {
        menuCode: this.formInline2.menuCode,
        fieldList: this.userMenuShowFields,
      };
      this.insertLoading = true;
      insertUserFieldRelation(data).then((res) => {
        this.insertLoading = false;
        if (res.code == 1) {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success',
          });
          this.closeConfigTableDialog();
        } else {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'error',
          });
        }
      });
    },
    //是否全选字段
    isAllFieldChange(val) {
      this.userMenuShowFields = val ? this.userMenuAllFields : [];
      this.formInline2.isIndeterminate = false;
    },
    //是否选中单个字段
    isSingleFieldChange(val) {
      let checkedCount = this.userMenuShowFields.length;
      this.formInline2.isAll = checkedCount === this.userMenuAllFields.length;
      this.formInline2.isIndeterminate =
        checkedCount > 0 && checkedCount < this.userMenuAllFields.length;
    },
    //获取字段勾选状态
    getUserMenuFieldStatus(fieldCode) {
      if (this.userMenuShowFields != null) {
        for (let i = 0; i < this.userMenuShowFields.length; i++) {
          if (this.userMenuShowFields[i] == fieldCode) {
            return true;
          }
        }
        return false;
      }
    },
    //是否显示字段
    isShow(fieldCode) {
      if (this.formInline2.isAll || this.getUserMenuFieldStatus(fieldCode)) {
        return true;
      } else {
        return false;
      }
    },
    _getmemberinfo() {
      let data = {
        size: 99,
        current: 1,
        condition: {},
        ascs: [],
        descs: [],
      };
      getmemberrule(data).then((res) => {
        this.options = res.records;
      });
    },
    edit(v) {
      this.$router.push({
        name: 'queryExchangeFormDetail',
        params: {
          v: v,
        },
      });
    },
    handleChange(file, fileList) {
      this.fileList = fileList.slice(-1);
    },
    upload(res, file, fileList) {
      this.importLoading = false;
      if (res.code == 1) {
        this.$message({
          showClose: true,
          duration: 0,
          message: res.message,
          type: 'success',
        });
        this.closeConfigTableDialog();
        this.search();
      } else {
        this.fieldList = [];
        this.$message({
          showClose: true,
          message: res.message,
          type: 'error',
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.el-form-item .el-select {
  width: 100%;
}
#configTableDiv .el-divider--horizontal {
  margin-top: 0;
}
</style>
